# coding: utf-8
from typing import List

class Solution:
    # 将矩阵顺时针旋转90°
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        size = len(matrix)
        # 先上下翻转，再对角翻转
        half_size = size // 2
        for i in range(half_size):
            for j in range(size):
                matrix[i][j],matrix[size-i-1][j] = matrix[size-i-1][j],matrix[i][j]

        for i in range(size-1,-1,-1):
            for j in range(i+1):
                # print(i,j)
                matrix[i][j],matrix[j][i] = matrix[j][i],matrix[i][j]

        # print(matrix)

if __name__ == '__main__':
    solu = Solution()
    solu.rotate([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
